import matplotlib.pyplot as plt
import csv

import numpy as np
from scipy.interpolate import make_interp_spline

'''读取csv文件'''


def readcsv(files):
    csvfile = open(files, 'r')
    plots = csv.reader(csvfile, delimiter=',')
    x = []
    y = []
    # 读取csv文件中2,3列的数据，且转化为float类型
    for row in plots:
        y.append(float(row[2]))
        x.append(float(row[1]))
    return x, y


# 读取5个文件
x2, y2 = readcsv(r"C:\Users\admin\Desktop\论文第二稿\实验结果\ndcg@10\run-NRMS-tag-Validation_nDCG@10.csv")
x2_smooth = np.linspace(min(x2), max(x2), 20)
y2_smooth = make_interp_spline(x2, y2)(x2_smooth)
plt.plot(x2_smooth, y2_smooth, label='NRMS', marker='x', markersize='7', markeredgewidth='1', markevery=3,
         linewidth='1.5')

x, y = readcsv(r"C:\Users\admin\Desktop\论文第二稿\实验结果\ndcg@10\run-NAML-tag-Validation_nDCG@10.csv")
x_smooth = np.linspace(min(x), max(x), 20)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.plot(x_smooth, y_smooth, label='NAML', marker='o', markersize='7', markeredgewidth='1', markevery=3,
         linewidth='1.5')

x1, y1 = readcsv(r"C:\Users\admin\Desktop\论文第二稿\实验结果\ndcg@10\run-TANR-tag-Validation_nDCG@10.csv")
x1_smooth = np.linspace(min(x1), max(x1), 20)
y1_smooth = make_interp_spline(x1, y1)(x1_smooth)
plt.plot(x1_smooth, y1_smooth, label='TANR', marker='*', markersize='7', markeredgewidth='1', markevery=3,
         linewidth='1.5')

x4, y4 = readcsv(r"C:\Users\admin\Desktop\论文第二稿\实验结果\ndcg@10\run-MyModel-tag-Validation_nDCG@10.csv")
x4_smooth = np.linspace(min(x4), max(x4), 20)
y4_smooth = make_interp_spline(x4, y4)(x4_smooth)
plt.plot(x4_smooth, y4_smooth, label='MAR', marker='|', markersize='7', markeredgewidth='1', markevery=3,
         linewidth='1.5')

x5, y5 = readcsv(r"C:\Users\admin\Desktop\论文第二稿\实验结果\ndcg@10\run-LSTUR-tag-Validation_nDCG@10.csv")
x5_smooth = np.linspace(min(x5), max(x5), 20)
y5_smooth = make_interp_spline(x5, y5)(x5_smooth)
plt.plot(x5_smooth, y5_smooth, label='LSTUR', marker='d', markersize='7', markeredgewidth='1', markevery=3,
         linewidth='1.5')

plt.xlabel("step", fontsize=15)
plt.ylabel("nDCG@10", fontsize=15)
plt.legend()
plt.show()
